//生成所有 指挥部
private ["_max", "_marker", "_pos", "_must", "_dis_mk"];
_max = as_num_e5;
_dis_mk = 8000;



for "_i" from 1 to _max do
{
	sleep 0.1;
	
	if(true) then
	{
		private _time = time + 20;//超时就缩小一倍
		private _pos_mk = [as_map_x + random as_map_w, as_map_y + random as_map_h];
		while{!([_pos_mk, 50] call fn_checkPos) 
		|| {[_pos_mk, _dis_mk * 0.5 * as_near_scale,"mk_e5_"] call fn_checkNearMarker}
		|| {_pos_mk distance2D as_start_pos < _dis_mk * 0.5 * as_near_scale}}do
		{
			_pos_mk = [as_map_x + random as_map_w, as_map_y + random as_map_h];
			if(time > _time) then{_dis_mk = _dis_mk * 0.5; _time = time + 20;};
		};
		
		_marker = createMarker [format["mk_e5_%1", _i], _pos_mk];
		

		
		//设置标记
		if(Param_ShowMarker > 0) then
		{
			_marker setMarkerShape "ICON";
			if(Param_ShowEnd == 1 || Param_ShowMarker == 2) then
			{
				_marker setMarkerType "hd_unknown";
				_marker setMarkerColor "ColorRed";
			}
			else
			{
				_marker setMarkerType "hd_dot";
				_marker setMarkerColor "ColorRed";
			};
			_marker setMarkerDir 0;	
		};
		
		
		[_marker] spawn
		{
			_marker = _this select 0;
			waitUntil{sleep 5;!isNil "as_show_e5"};
			_marker setMarkerType "hd_unknown";
			_marker setMarkerColor "ColorRed";
		};
		
		[_marker] spawn
		{
			private ["_end", "_marker", "_pos", "_init", "_dir", "_player"];	
			_marker = _this select 0;
			_pos = getMarkerPos _marker;
			_dir = markerDir _marker;
			_end = false;
			_init = false;
			//等待玩家靠近再生成
			while{!_init} do
			{
				uiSleep 10;
				if(as_npc_dead) exitWith{deleteMarker _marker};
				{
					if(!_init && {(_x distance getMarkerPos _marker) < 1500} && {speed _x < 200}) then
					{
						_init = true;
						_pos call (selectRandom as_all_e5);
					};
				}forEach AllPlayers;
			};
			if(as_npc_dead) exitWith{deleteMarker _marker};
			//据点统计,这里可能点被删掉，所以之后再统计
			as_num_e_num_all = as_num_e_num_all + 1;
			publicVariable "as_num_e_num_all";	
			while{!_end} do
			{
				sleep 5;
				{
					if((_x distanceSqr getMarkerPos _marker) < 10000) exitWith
					{
						_marker setMarkerShape "ICON";
						_marker setMarkerType "n_hq";
						_marker setMarkerColor "ColorBlue";
						_marker setMarkerDir 0;
						_end = true;
						//[_x, localize "STR_TAG_O_14"] remoteExec ["sideChat"];
						_x remoteExec ["fnc_findE5"];
						_player = _x;
						
						if(isNil "as_e5_find")then{
							"LeadTrack01_F_EPA" remoteExec ["playMusic"];
						};
						
						//同步任务
						as_e5_find = true;
						publicVariable "as_e5_find";
					};
				}forEach (call fn_getPlayerRed);
			};
			
			//靠特别近代表被玩家占领
			[_marker]spawn
			{
				params["_marker"];
				private _end = false;
				while {!_end} do
				{
					sleep 45;
					{
						if(_x distance (getMarkerPos _marker) < 3) exitWith
						{
							_end = true;
						};
					}forEach (call fn_getPlayerRed);
				};
				_marker setMarkerColor "ColorGrey";
				as_num_e_num_hold = as_num_e_num_hold + 1;
				publicVariable "as_num_e_num_hold";
			};
			
			//被发现后 创建支援
			[0, asg_6, getPos _player, 800, 0, 1] spawn fn_createGN;
			sleep 15;
			[0, asg_6, getPos _player, 800, 0, 1] spawn fn_createGN;
			
			[getPos _player, 1.25] spawn fn_aiNeedSupport;
			
			
			//呆了太久
			sleep 720;	
			{
				if((_x distanceSqr getMarkerPos _marker) < 40000) exitWith
				{
					[0, selectRandom[asg_21, asg_22], getPos _x, 1200, 0, 1] spawn fn_createGN;
					[getPos _x, 1.5] spawn fn_aiNeedSupport;
				};
			}forEach (call fn_getPlayerRed);
		};
	};
};

